package com.zbkj.service.service.order.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.dal.base.constants.OrderConstants;
import com.zbkj.dal.base.enums.OrderStatusEnums;
import com.zbkj.dal.common.utils.CrmebUtil;
import com.zbkj.dal.dao.CouponDao;
import com.zbkj.dal.dao.OrderDao;
import com.zbkj.dal.entity.coupon.Coupon;
import com.zbkj.dal.entity.order.Order;
import com.zbkj.dal.entity.user.User;
import com.zbkj.dal.pojo.request.order.merchant.AdminMerchantOfflineOrderCreateRequest;
import com.zbkj.service.service.MerchantOrderService;
import com.zbkj.service.service.UserService;
import com.zbkj.service.service.order.merchant.AdminMerchantOfflineOrderV2Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author wangzhengyan
 * @date 2024/4/12 3:10 PM
 */
@Service
@Slf4j
public class AdminMerchantOfflineOrderV2ServiceImpl extends ServiceImpl<OrderDao, Order> implements AdminMerchantOfflineOrderV2Service {
    @Resource
    private UserService userService;
    @Autowired
    private MerchantOrderService merchantOrderService;
    @Resource
    private OrderDao orderDao;


    @Override
    @Transactional(rollbackFor =Exception.class)
    public Boolean createOfflineOrder(AdminMerchantOfflineOrderCreateRequest request) {
        // 默认订单已完成
        Order order = new Order();
        String orderNo = CrmebUtil.getOrderNo(OrderConstants.ORDER_PREFIX_MERCHANT);
        User user = userService.getInfo();
        order.setOrderNo(orderNo);
        order.setMerId(0);
        order.setUid(user.getId());
        order.setTotalNum(1);
        order.setProTotalPrice(request.getOrderTotalAmount());
        order.setTotalPrice(request.getOrderTotalAmount());
//        order.setCouponPrice();
//        order.setUseIntegral();
        order.setIntegralPrice(request.getDeductionAmount());
        order.setPayPrice(request.getOrderActualAmount());
//        order.setPayPostage();
        order.setPaid(Boolean.TRUE);
        order.setPayTime(new Date());
        order.setPayType(request.getPayType());
//        order.setPayChannel();
        order.setStatus(OrderStatusEnums.COMPLETE.code());
//        order.setRentStatus();
//        order.setRefundStatus();
//        order.setCancelStatus();
//        order.setIsUserDel();
//        order.setIsMerchantDel();
//        order.setGainIntegral();
//        order.setOutTradeNo();
//        order.setRedirect();
        order.setType(request.getOrderType());
        order.setLevel(1);
//        order.setPlatOrderNo();
        order.setIsDel(Boolean.FALSE);
//        order.setReceivingTime();
        order.setCreateTime(LocalDateTime.now());
//        order.setUpdateTime(new Date());
//        order.setMerCouponPrice();
//        order.setPlatCouponPrice();
//        order.setPlatCouponId();
//        order.setRentReturnType();
      orderDao.insert(order);

        return Boolean.TRUE;
    }
}
